﻿#include "socket.h"
#include <iostream>
#include <unistd.h>
int main()
{
    Socket socket;
    socket.createTcpClient(58888, "127.0.0.1");
    int n = 5;
    while(n--) 
    {
        std::string msg = "hello, server";
        socket.send(msg.c_str(), msg.size());
        char buf[1024];
        ssize_t ret = socket.recv(buf, sizeof(buf));
        if(ret < 0)
        {
            std::cout << "server disconnected, client_fd: " << socket.fd() << std::endl;
            break;
        }
        buf[ret] = '\0';
        std::cout << "recv: " << buf << std::endl;
        sleep(1);
    }
    while(1) sleep(1);
    socket.close();
    return 0;
}